﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;

namespace SharpSoft.IO.Ports
{
    public static class SerialPortExtension
    {
        /// <summary>
        /// 发送十六进制字符串
        /// </summary>
        /// <param name="serialPort"></param>
        /// <param name="hex"></param>
        public static void SendHexString(this SerialPort serialPort, string hex)
        {
            var data = HexHelper.HexToBytes(hex, true);
            if (!serialPort.IsOpen)
            {
                throw new Exception("串口未打开。");
            }
            serialPort.Write(data, 0, data.Length);
        }


    }
}
